package com.ashin.module.hello.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.time.LocalDateTime;

@RestController
@RequiredArgsConstructor
public class HelloController {

    private final RedisTemplate<String, Object> redisTemplate;

    @GetMapping(value = {"/index", "/"})
    public String hello() throws UnknownHostException {
        return "Hello k8s " + LocalDateTime.now() + " " + InetAddress.getLocalHost().getHostAddress();
    }


    @GetMapping(value = {"/redis/{key}/{value}"})
    public Object redisOp(@PathVariable("key") String key, @PathVariable("value") String value) {
        redisTemplate.opsForValue().set(key, value);

        return redisTemplate.opsForValue().get(key);
    }
}
